A comprehensive test automation framework built with Python, Selenium WebDriver, and Behave for BDD testing. The framework supports both UI and API testing using Behavior-Driven Development (BDD) with Gherkin syntax, including BrowserStack cloud testing integration.
- BDD Framework - Complete Behavior-Driven Development with Behave
- Page Object Model (POM) - Clean, maintainable test structure
- Multi-browser Support - Chrome, Firefox, Safari with headless/headed modes
- BrowserStack Integration - Cloud testing on real devices and browsers
- API Testing - REST API testing with pytest-based tests
- Gherkin Syntax - Human-readable test scenarios
- Real API Integration - JSONPlaceholder API for testing
- Rich Reporting - Behave reports, Allure reports, and framework summaries
- Cross-platform - Windows, macOS, Linux support
- Test Coverage - Complete coverage of UI and API test cases
- Flexible Execution - Local and cloud testing options
Interactive Menu:
python quick_tests.pyMain Commands:
# Local UI tests
python run_tests.py --type ui --env local
# UI tests with Allure reporting
python run_tests.py --type ui --env local --allure
# BrowserStack UI tests
python run_tests.py --type ui --env browserstack
# API tests
python run_tests.py --type api
# All tests
python run_tests.py --type all --env localAllure Reporting:
# UI tests with Allure reports
python run_ui_tests_allure.py
# Using Makefile
make test-ui-allureBrowserStack Setup:
# Set credentials
export BROWSERSTACK_ENABLED=true
export BROWSERSTACK_USERNAME=your_username
export BROWSERSTACK_ACCESS_KEY=your_access_key
# Run on BrowserStack
python run_tests.py --type ui --env browserstack --platform 0selenium-python-framework/
βββ π§ͺ Test Files
β βββ run_tests.py # Main test runner (UI + API)
β βββ quick_tests.py # Interactive test menu
β βββ test_configs.py # Test configurations
β βββ features/ # BDD Feature Files (UI only)
β β βββ login.feature # UI Login scenarios
β β βββ cart.feature # UI Cart scenarios
β β βββ steps/ # Step Definitions
β β β βββ login_steps.py # UI Login step definitions
β β β βββ cart_steps.py # UI Cart step definitions
β β βββ env.py # Behave environment setup
β β βββ behave.ini # Behave configuration
β βββ api_tests/ # Pytest-based API Tests
β βββ test_api_cases.py # Focused API tests (4 test cases)
β βββ test_users_api.py # Comprehensive Users API tests
β βββ test_posts_api.py # Comprehensive Posts API tests
β βββ test_comments_api.py # Comprehensive Comments API tests
β βββ conftest.py # Pytest configuration
β βββ utils.py # API test utilities
β βββ schemas/ # JSON Schema files
β βββ user_schema.json
β βββ users_array_schema.json
β βββ post_schema.json
β βββ comment_schema.json
β βββ created_user_schema.json
βββ π οΈ Utilities
β βββ stop_tests.py # Stop running tests
β βββ force_quit_browserstack.py # Force quit BrowserStack sessions
β βββ fix_browserstack_status.py # Fix build status issues
β βββ update_build_status.py # Update BrowserStack build status
β βββ utils/ # Core utilities
β βββ config.py # Configuration settings
β βββ helpers.py # Helper functions
β βββ browserstack_helper.py # BrowserStack integration
βββ ποΈ Core Directories
β βββ pages/ # Page Object Model
β β βββ base_page.py # Base page class
β β βββ login_page.py # Login page object
β β βββ inventory_page.py # Inventory page object
β β βββ cart_page.py # Cart page object
β βββ reports/ # Generated test reports
β βββ allure_results/ # Allure test results
β βββ allure-report/ # Generated Allure reports
β βββ pytest_html/ # Pytest HTML reports
β βββ focused_api/ # Focused API test reports
β βββ screenshots/ # Test screenshots
βββ βοΈ Configuration
β βββ browserstack.yml # BrowserStack configuration
β βββ browserstack.env # BrowserStack environment variables
β βββ env.example # Environment variables template
β βββ pytest.ini # Pytest configuration
β βββ requirements.txt # Python dependencies
β βββ Makefile # Build commands
βββ π Documentation
β βββ TEST_EXECUTION_GUIDE.md # Comprehensive execution guide
β βββ EXECUTION_SUMMARY.md # Quick reference summary
β βββ BROWSERSTACK_CLEANUP_GUIDE.md # BrowserStack troubleshooting
β βββ README.md # This file
βββ test_env/ # Python virtual environment
βββ bin/ # Virtual environment binaries
βββ lib/ # Python packages
βββ pyvenv.cfg # Virtual environment config
- Python 3.9 or higher
- pip (Python package installer)
- Git
-
Clone the repository
git clone <repository-url> cd selenium-python-framework
-
Create a virtual environment
python -m venv venv # On Windows venv\Scripts\activate # On macOS/Linux source venv/bin/activate
-
Install dependencies
pip install -r requirements.txt
-
Install WebDriver The framework uses
webdriver-managerto automatically manage WebDriver binaries.
For cloud testing on BrowserStack:
-
Get BrowserStack credentials
- Sign up at BrowserStack
- Get your username and access key
-
Configure BrowserStack
# Copy environment template cp env.example browserstack.env # Edit browserstack.env with your credentials nano browserstack.env
-
Set environment variables
# Enable BrowserStack export BROWSERSTACK_ENABLED=true export BROWSERSTACK_USERNAME=your_username export BROWSERSTACK_ACCESS_KEY=your_access_key export BROWSERSTACK_PLATFORM_INDEX=0 # 0=Chrome, 1=Firefox, 2=Safari
Interactive Test Menu:
python quick_tests.pyMain Test Runner:
# UI tests (local)
python run_tests.py --type ui --env local
# UI tests (BrowserStack)
python run_tests.py --type ui --env browserstack
# API tests
python run_tests.py --type api
# All tests
python run_tests.py --type allEnvironment Selection:
# Local testing (Chrome, Firefox, Safari)
python run_tests.py --type ui --env local --browser chrome
python run_tests.py --type ui --env local --browser firefox
python run_tests.py --type ui --env local --browser safari
# BrowserStack cloud testing
python run_tests.py --type ui --env browserstack --platform 0 # Chrome
python run_tests.py --type ui --env browserstack --platform 1 # FirefoxTest Type Selection:
# UI tests only (Behave BDD)
python run_tests.py --type ui --env local
# UI tests with Allure reporting
python run_tests.py --type ui --env local --allure
# API tests only (Pytest)
python run_tests.py --type api
# All tests (UI + API)
python run_tests.py --type all --env localFeature Selection:
# Specific feature files
python run_tests.py --type ui --env local --feature features/login.feature
python run_tests.py --type ui --env local --feature features/cart.feature
# Multiple features
python run_tests.py --type ui --env local --feature features/login.feature features/cart.featureHeadless Mode:
# Run in headless mode (no browser window)
python run_tests.py --type ui --env local --headless
# Run with visible browser
python run_tests.py --type ui --env local --no-headlessQuick test execution:
# Run all UI tests
make test-ui
# Run focused API tests with HTML report
make test-focused-api-html
# Run all tests
make test-all
# Run tests with coverage
make test-completeRun all BDD tests (UI + API):
python3 run_complete_tests.py --type bddUI Tests with Allure Reporting:
# Dedicated Allure runner
python3 run_ui_tests_allure.py
# Using main test runner
python3 run_tests.py --type ui --env local --allure
# Using Makefile
make test-ui-allureAllure Report Management:
# Generate static Allure report
allure generate reports/allure_results/ --clean -o reports/allure-report
# Serve interactive Allure report (opens in browser)
allure serve reports/allure_results
# View static report
open reports/allure-report/index.htmlAllure Report Features:
- Interactive Dashboard - Visual overview of test execution
- Step-by-Step Details - Detailed execution logs with screenshots
- Timeline View - Chronological test execution timeline
- Categories & Filtering - Filter tests by status, feature, or tags
- Screenshot Attachments - Visual debugging support
- Trend Analysis - Historical test execution trends
Run all UI tests:
# Using complete test runner
python3 run_complete_tests.py --type bdd
# Using Makefile
make test-ui
# Direct Behave command
behave features/login.feature features/cart.feature --no-captureRun specific UI features:
# Login tests only
behave features/login.feature --no-capture
# Cart tests only
behave features/cart.feature --no-captureBrowser modes:
# Headless mode (no browser window)
HEADLESS=true behave features/login.feature features/cart.feature --no-capture
make test-ui # Uses headless by default
# Headed mode (visible browser)
HEADLESS=false behave features/login.feature features/cart.feature --no-capture
make test-visible
# Specific browser
make test-chrome
make test-firefoxUI Test Coverage:
- β TC_UI_01: Successful login with valid credentials
- β TC_UI_02: Failed login with invalid password
- β TC_UI_03: Add single item to cart & complete order
- β TC_UI_04: Sort products by price low to high
BDD API tests have been removed - API testing is now handled by Pytest for better maintainability and reporting.
Run all API tests:
# Using complete test runner
python3 run_complete_tests.py --type api
# Using Makefile
make test-focused-api-html
# Direct focused API tests
python3 run_focused_api_html.pyFocused API Tests (4 Test Cases):
# With JSON report
python3 run_focused_api_tests.py
make test-focused-api
# With HTML report
python3 run_focused_api_html.py
make test-focused-api-htmlComprehensive API Tests (if pytest works):
# All API tests
python -m pytest api_tests/ -v --html=reports/pytest_html/pytest_api_report.html --self-contained-html
# Specific test modules
python -m pytest api_tests/test_users_api.py -v
python -m pytest api_tests/test_posts_api.py -v
python -m pytest api_tests/test_comments_api.py -v
# By markers
python -m pytest api_tests/ -m smoke -v
python -m pytest api_tests/ -m regression -v
python -m pytest api_tests/ -m api -vAPI Test Coverage:
Focused API Tests (4 Test Cases):
- β TC_API_01: Fetch user list - GET /api/users
- β TC_API_02: Create a new user - POST /api/users
- β TC_API_03: Valid login - POST /api/login
- β TC_API_04: Missing password - POST /api/login
Comprehensive API Tests:
- β Users API: GET, POST, PUT, PATCH, DELETE with JSON Schema validation
- β Posts API: GET, POST, PUT, PATCH, DELETE with JSON Schema validation
- β Comments API: GET, POST, PUT, PATCH, DELETE with JSON Schema validation
- β Performance Testing: Response time validation
- β Data Consistency: Multiple request validation
- β Error Handling: Invalid data and edge cases
Run everything:
# Complete test suite (UI + API)
python3 run_complete_tests.py --type all
# Using Makefile
make test-allUI Testing:
# All UI tests
make test-ui
# UI tests with visible browser
make test-visible
# Specific UI features
behave features/login.feature --no-capture
behave features/cart.feature --no-captureAPI Testing:
# Focused API tests with HTML report
make test-focused-api-html
# Focused API tests with JSON report
make test-focused-api
# Direct execution
python3 run_focused_api_html.pyReporting:
# Generate Allure reports
python3 run_with_allure.py
# View Allure reports
python3 view_allure_report.py
# Open HTML reports
open reports/pytest_html/focused_api_report.htmlTest Execution:
make test-ui # Run UI tests (headless)
make test-ui-allure # Run UI tests with Allure reporting
make test-visible # Run UI tests (visible browser)
make test-focused-api # Run focused API tests (JSON report)
make test-focused-api-html # Run focused API tests (HTML report)
make test-all # Run all tests
make test-complete # Run all tests with coverageBrowser-specific:
make test-chrome # Run tests on Chrome
make test-firefox # Run tests on Firefox
make test-headless # Run tests in headless modeReporting:
make reports # Generate all reports
make allure # Generate Allure reports
make view-allure # View Allure reports in browserSetup:
make install # Install dependencies
make setup # Setup test environment
make help # Show all available commandsUI Test Cases:
- β TC_UI_01: Successful login with valid credentials
- β TC_UI_02: Failed login with invalid password
- β TC_UI_03: Add single item to cart and complete order (E2E checkout flow)
- β TC_UI_04: Sort products by price low to high
API Test Cases:
- β TC_API_01: Fetch user list - GET /api/users
- β TC_API_02: Create a new user - POST /api/users
- β TC_API_03: Valid login - POST /api/login
- β TC_API_04: Missing password - POST /api/login
Comprehensive API Tests:
- β Users API: GET, POST, PUT, PATCH, DELETE with JSON Schema validation
- β Posts API: GET, POST, PUT, PATCH, DELETE with JSON Schema validation
- β Comments API: GET, POST, PUT, PATCH, DELETE with JSON Schema validation
- β Performance Testing: Response time validation
- β Data Consistency: Multiple request validation
- β Error Handling: Invalid data and edge cases
The framework generates comprehensive test reports:
- Location:
reports/behave/ - Text and JSON format reports
- Detailed step-by-step execution logs
- Location:
reports/allure-report/ - Interactive HTML reports with rich visualizations
- Test execution timeline and trends
- Screenshot attachments for each step
- Test case categorization and filtering
- Location:
reports/framework_summary.json - Complete test execution summary
- Test case coverage and results
- Location:
reports/screenshots/ - Test failure screenshots
- Visual debugging support
- Step-by-step execution screenshots
python3 generate_reports.pyA comprehensive test runner that executes all BDD tests and generates Allure reports automatically.
Features:
- Runs all BDD tests with Allure formatter
- Automatically generates Allure reports
- Handles test result file organization
- Provides detailed execution feedback
- Error handling and status reporting
Usage:
python3 run_with_allure.pyWhat it does:
- Creates
reports/allure_results/directory - Runs all BDD tests with Allure formatter
- Generates interactive Allure report
- Provides report locations and viewing instructions
A dedicated utility for running UI tests with Allure reporting.
Features:
- Runs all UI tests with Allure formatter
- Automatically generates Allure reports
- Handles test result file organization
- Provides detailed execution feedback
- Error handling and status reporting
- Interactive report serving option
Usage:
# Run UI tests with Allure reporting
python3 run_ui_tests_allure.py
# Serve interactive report
python3 run_ui_tests_allure.py --serveWhat it does:
- Creates
reports/allure_results/directory - Runs UI tests with Allure formatter
- Generates static Allure report
- Provides report locations and viewing instructions
- Optionally serves interactive report
A convenient utility to open Allure reports in your default browser.
Features:
- Automatically starts Allure server
- Opens report in default browser
- Handles server lifecycle management
- Validates test result files before serving
- Graceful shutdown with Ctrl+C
Usage:
python3 view_allure_report.pyWhat it does:
- Checks for existing test results
- Starts Allure serve process
- Opens report in browser automatically
- Keeps server running until stopped
- Interactive Dashboard: Visual overview of test execution
- Test Case Details: Step-by-step execution with screenshots
- Timeline View: Chronological test execution timeline
- Categories: Test categorization (passed, failed, skipped)
- Trends: Historical test execution trends
- Attachments: Screenshots and logs for each step
- Filtering: Filter tests by status, feature, or tags
Edit features/behave.ini to modify BDD test settings:
[behave]
paths = features
default_format = pretty
environment_file = env.pySet environment variables for test execution:
# Browser mode
HEADLESS=true # Run in headless mode
HEADLESS=false # Run in headed mode (visible browser)
# API base URL
API_BASE_URL=https://jsonplaceholder.typicode.comEdit pages/ classes to modify element locators and page interactions.
The framework uses Gherkin syntax for test scenarios:
login.feature- UI login scenarioscart.feature- UI cart and inventory scenariosapi_login.feature- API login scenariosapi_users.feature- API user management scenarios
login_steps.py- UI login step implementationscart_steps.py- UI cart step implementationsapi_steps.py- API step implementations
Each feature file contains multiple scenarios covering:
- Happy path testing
- Error handling
- Edge cases
- Data validation
# Run complete BDD test suite
python3 run_complete_tests.py --type bdd
# Run with Allure reporting
python3 run_with_allure.py
# View Allure report in browser
python3 view_allure_report.py
# Run with specific browser mode
HEADLESS=true python3 run_complete_tests.py --type bdd
# Generate comprehensive reports
python3 generate_reports.pyThe framework is designed to integrate with CI/CD systems:
- GitHub Actions
- Jenkins
- GitLab CI
- Azure DevOps
- Headed Mode: Visible browser for debugging
- Headless Mode: Background execution for CI/CD
- API Testing: Real HTTP endpoint testing
- UI Testing: Selenium WebDriver automation
Create new .feature files in the features/ directory:
Feature: New Feature
As a user
I want to perform some action
So that I can achieve a goal
Scenario: Test scenario
Given some precondition
When I perform an action
Then I should see expected resultCreate step definitions in features/steps/:
from behave import given, when, then
@given('some precondition')
def step_precondition(context):
# Implementation here
pass
@when('I perform an action')
def step_action(context):
# Implementation here
pass
@then('I should see expected result')
def step_verification(context):
# Assertions here
passExtend BasePage for new page objects:
from pages.base_page import BasePage
class MyPage(BasePage):
# Locators
ELEMENT_LOCATOR = (By.ID, "element-id")
def __init__(self, driver):
super().__init__(driver)
def perform_action(self):
self.click_element(self.ELEMENT_LOCATOR)Feature: User Login
Scenario: Successful login
Given the user is on the login page
When the user enters username "standard_user"
And the user enters password "secret_sauce"
And the user clicks the login button
Then the user should be redirected to the inventory page# Run with visible browser for debugging
HEADLESS=false behave features/login.feature --no-captureimport logging
logging.basicConfig(level=logging.DEBUG)Screenshots are automatically saved to reports/screenshots/ on test failures.
Add print statements in step definitions:
@when('I perform an action')
def step_action(context):
print("π Debug: Performing action...")
# Implementation here
print("β
Debug: Action completed")- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Run the test suite
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
For questions and support:
- Check the documentation
- Search existing issues
- Create a new issue with detailed information
- Contact the maintainers
Session Management:
# List running BrowserStack sessions
python force_quit_browserstack.py --list
# Force quit all running sessions
python force_quit_browserstack.py --quit
# Fix build status issues
python fix_browserstack_status.py
# Update build status
python update_build_status.py --updateSession URLs and Build Names:
- Every BrowserStack execution displays session URLs
- Unique build names with timestamps
- Real-time session monitoring
- Automatic cleanup after test completion
Supported Platforms:
- Platform 0: Chrome (Latest)
- Platform 1: Firefox (Latest)
- Platform 2: Safari (Latest)
browserstack.yml:
platforms:
- browserName: Chrome
browserVersion: latest
os: OS X
osVersion: Sonoma
- browserName: Firefox
browserVersion: latest
os: OS X
osVersion: Sonoma
- browserName: Safari
browserVersion: latest
os: OS X
osVersion: SonomaEnvironment Variables:
BROWSERSTACK_ENABLED=true
BROWSERSTACK_USERNAME=your_username
BROWSERSTACK_ACCESS_KEY=your_access_key
BROWSERSTACK_PLATFORM_INDEX=0- v1.0.0 - Initial release with basic framework
- v1.1.0 - Added BDD support and API testing
- v1.2.0 - Enhanced reporting and CI/CD integration
- v2.0.0 - Complete BDD framework with cleaned structure
- v2.1.0 - BrowserStack cloud testing integration
- Added BrowserStack support for cloud testing
- Interactive test execution menu
- Enhanced test runner with environment selection
- Browser and platform selection options
- Session management utilities
- Build status monitoring
- Comprehensive cleanup tools
- Updated project structure and documentation
- New Allure Runner:
run_ui_tests_allure.pyfor dedicated Allure reporting - Enhanced Test Runner: Added
--allureflag torun_tests.py - Makefile Integration:
make test-ui-allurecommand - Rich Visual Reports: Interactive dashboards with screenshots and timelines
- Updated TC_UI_03: Now includes complete E2E checkout flow
- Focused API Tests: Streamlined to 4 essential test cases
- Security Updates: Updated black formatter to resolve CVE-2024-21503
- Comprehensive README: Updated with all new features and commands
- Clear Examples: Step-by-step instructions for all functionality
- Multiple Execution Options: Local, BrowserStack, and Allure reporting
Happy Testing! π